<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="承租人姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入承租人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="承租人身份证" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入承租人身份证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承租人手机号" prop="userPhoneNumber">
        <el-input
          v-model="queryParams.userPhoneNumber"
          placeholder="请输入承租人手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承租人证件有效期 (yyyy-MM-dd, 9999-99-99)" prop="certValidDate">
        <el-date-picker clearable
          v-model="queryParams.certValidDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择承租人证件有效期 (yyyy-MM-dd, 9999-99-99)">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="支付宝账号信息 (租借商品用户的支付宝uid)" prop="alipayUid">
        <el-input
          v-model="queryParams.alipayUid"
          placeholder="请输入支付宝账号信息 (租借商品用户的支付宝uid)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户在支付宝应用下的 openId" prop="userOpenId">
        <el-input
          v-model="queryParams.userOpenId"
          placeholder="请输入用户在支付宝应用下的 openId"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户的支付宝应用 appId" prop="merchantAppId">
        <el-input
          v-model="queryParams.merchantAppId"
          placeholder="请输入商户的支付宝应用 appId"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出租企业名称" prop="leaseCorpName">
        <el-input
          v-model="queryParams.leaseCorpName"
          placeholder="请输入出租企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出租企业统一社会信用代码" prop="leaseCorpId">
        <el-input
          v-model="queryParams.leaseCorpId"
          placeholder="请输入出租企业统一社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出租法定代表人姓名" prop="leaseCorpOwnerName">
        <el-input
          v-model="queryParams.leaseCorpOwnerName"
          placeholder="请输入出租法定代表人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业执照对应的名称 (企业类型必填)" prop="leasedEnterprise">
        <el-input
          v-model="queryParams.leasedEnterprise"
          placeholder="请输入营业执照对应的名称 (企业类型必填)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平台注册的电话" prop="registeredTelephoneNumber">
        <el-input
          v-model="queryParams.registeredTelephoneNumber"
          placeholder="请输入平台注册的电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承租企业实际控制人身份证号" prop="actualControllerId">
        <el-input
          v-model="queryParams.actualControllerId"
          placeholder="请输入承租企业实际控制人身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承租企业实际控制人手机号" prop="actualControllerNumber">
        <el-input
          v-model="queryParams.actualControllerNumber"
          placeholder="请输入承租企业实际控制人手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承租企业实际控制人姓名" prop="actualControllerName">
        <el-input
          v-model="queryParams.actualControllerName"
          placeholder="请输入承租企业实际控制人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承租企业统一社会信用代码" prop="businesslicenseNumber">
        <el-input
          v-model="queryParams.businesslicenseNumber"
          placeholder="请输入承租企业统一社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承租企业法定代表人姓名" prop="legalRepresentative">
        <el-input
          v-model="queryParams.legalRepresentative"
          placeholder="请输入承租企业法定代表人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="创建时间" prop="createdAt">
        <el-date-picker clearable
          v-model="queryParams.createdAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedAt">
        <el-date-picker clearable
          v-model="queryParams.updatedAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['trans:lesseeInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['trans:lesseeInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['trans:lesseeInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['trans:lesseeInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="lesseeInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="承租人姓名" align="center" prop="userName" min-width ="90"/>
      <el-table-column label="承租人身份证" align="center" prop="userId"  min-width ="100"/>
      <el-table-column label="承租人手机号" align="center" prop="userPhoneNumber" min-width ="100"/>
      <el-table-column label="承租人证件类型" align="center" prop="userType" min-width ="120"/>
      <el-table-column label="承租人证件有效期" align="center" prop="certValidDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.certValidDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付宝账号信息" align="center" prop="alipayUid" />
      <el-table-column label="用户在支付宝应用下的 openId" align="center" prop="userOpenId"  width="180"/>
      <el-table-column label="商户的支付宝应用 appId" align="center" prop="merchantAppId" />
      <el-table-column label="出租企业名称" align="center" prop="leaseCorpName" />
      <el-table-column label="出租企业统一社会信用代码" align="center" prop="leaseCorpId" />
      <el-table-column label="出租法定代表人姓名" align="center" prop="leaseCorpOwnerName" />
      <el-table-column label="租赁方类别" align="center" prop="lesseeType" />
      <el-table-column label="营业执照对应的名称" align="center" prop="leasedEnterprise" />
      <el-table-column label="租赁人身份证人像面照片地址" align="center" prop="userImageUrl" />
      <el-table-column label="租赁人身份证国徽面照片地址" align="center" prop="userBackImageUrl" />
      <el-table-column label="平台注册的电话" align="center" prop="registeredTelephoneNumber" />
      <el-table-column label="承租企业实际控制人身份证号" align="center" prop="actualControllerId" />
      <el-table-column label="承租企业实际控制人手机号" align="center" prop="actualControllerNumber" />
      <el-table-column label="承租企业实际控制人姓名" align="center" prop="actualControllerName" />
      <el-table-column label="承租企业实际控制人身份证人像面地址" align="center" prop="actualControllerImageUrl" />
      <el-table-column label="承租企业实际控制人身份证国徽面地址" align="center" prop="actualControllerBackImageUrl" />
      <el-table-column label="承租企业统一社会信用代码" align="center" prop="businesslicenseNumber" />
      <el-table-column label="承租企业营业执照地址" align="center" prop="businesslicenseUrl" />
      <el-table-column label="承租企业法定代表人姓名" align="center" prop="legalRepresentative" />
      <el-table-column label="创建时间" align="center" prop="createdAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updatedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['trans:lesseeInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['trans:lesseeInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改承租人信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="承租人姓名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入承租人姓名" />
        </el-form-item>
        <el-form-item label="承租人身份证" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入承租人身份证" />
        </el-form-item>
        <el-form-item label="承租人手机号" prop="userPhoneNumber">
          <el-input v-model="form.userPhoneNumber" placeholder="请输入承租人手机号" />
        </el-form-item>
        <el-form-item label="承租人证件有效期 (yyyy-MM-dd, 9999-99-99)" prop="certValidDate">
          <el-date-picker clearable
            v-model="form.certValidDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择承租人证件有效期 (yyyy-MM-dd, 9999-99-99)">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付宝账号信息 (租借商品用户的支付宝uid)" prop="alipayUid">
          <el-input v-model="form.alipayUid" placeholder="请输入支付宝账号信息 (租借商品用户的支付宝uid)" />
        </el-form-item>
        <el-form-item label="用户在支付宝应用下的 openId" prop="userOpenId">
          <el-input v-model="form.userOpenId" placeholder="请输入用户在支付宝应用下的 openId" />
        </el-form-item>
        <el-form-item label="商户的支付宝应用 appId" prop="merchantAppId">
          <el-input v-model="form.merchantAppId" placeholder="请输入商户的支付宝应用 appId" />
        </el-form-item>
        <el-form-item label="出租企业名称" prop="leaseCorpName">
          <el-input v-model="form.leaseCorpName" placeholder="请输入出租企业名称" />
        </el-form-item>
        <el-form-item label="出租企业统一社会信用代码" prop="leaseCorpId">
          <el-input v-model="form.leaseCorpId" placeholder="请输入出租企业统一社会信用代码" />
        </el-form-item>
        <el-form-item label="出租法定代表人姓名" prop="leaseCorpOwnerName">
          <el-input v-model="form.leaseCorpOwnerName" placeholder="请输入出租法定代表人姓名" />
        </el-form-item>
        <el-form-item label="营业执照对应的名称 (企业类型必填)" prop="leasedEnterprise">
          <el-input v-model="form.leasedEnterprise" placeholder="请输入营业执照对应的名称 (企业类型必填)" />
        </el-form-item>
        <el-form-item label="租赁人身份证人像面照片地址" prop="userImageUrl">
          <el-input v-model="form.userImageUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="租赁人身份证国徽面照片地址" prop="userBackImageUrl">
          <el-input v-model="form.userBackImageUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="平台注册的电话" prop="registeredTelephoneNumber">
          <el-input v-model="form.registeredTelephoneNumber" placeholder="请输入平台注册的电话" />
        </el-form-item>
        <el-form-item label="承租企业实际控制人身份证号" prop="actualControllerId">
          <el-input v-model="form.actualControllerId" placeholder="请输入承租企业实际控制人身份证号" />
        </el-form-item>
        <el-form-item label="承租企业实际控制人手机号" prop="actualControllerNumber">
          <el-input v-model="form.actualControllerNumber" placeholder="请输入承租企业实际控制人手机号" />
        </el-form-item>
        <el-form-item label="承租企业实际控制人姓名" prop="actualControllerName">
          <el-input v-model="form.actualControllerName" placeholder="请输入承租企业实际控制人姓名" />
        </el-form-item>
        <el-form-item label="承租企业实际控制人身份证人像面地址" prop="actualControllerImageUrl">
          <el-input v-model="form.actualControllerImageUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="承租企业实际控制人身份证国徽面地址" prop="actualControllerBackImageUrl">
          <el-input v-model="form.actualControllerBackImageUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="承租企业统一社会信用代码" prop="businesslicenseNumber">
          <el-input v-model="form.businesslicenseNumber" placeholder="请输入承租企业统一社会信用代码" />
        </el-form-item>
        <el-form-item label="承租企业营业执照地址" prop="businesslicenseUrl">
          <el-input v-model="form.businesslicenseUrl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="承租企业法定代表人姓名" prop="legalRepresentative">
          <el-input v-model="form.legalRepresentative" placeholder="请输入承租企业法定代表人姓名" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdAt">
          <el-date-picker clearable
            v-model="form.createdAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedAt">
          <el-date-picker clearable
            v-model="form.updatedAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLesseeInfo, getLesseeInfo, delLesseeInfo, addLesseeInfo, updateLesseeInfo } from "@/api/trans/lesseeInfo";

export default {
  name: "LesseeInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 承租人信息表格数据
      lesseeInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        userId: null,
        userPhoneNumber: null,
        userType: null,
        certValidDate: null,
        alipayUid: null,
        userOpenId: null,
        merchantAppId: null,
        leaseCorpName: null,
        leaseCorpId: null,
        leaseCorpOwnerName: null,
        lesseeType: null,
        leasedEnterprise: null,
        userImageUrl: null,
        userBackImageUrl: null,
        registeredTelephoneNumber: null,
        actualControllerId: null,
        actualControllerNumber: null,
        actualControllerName: null,
        actualControllerImageUrl: null,
        actualControllerBackImageUrl: null,
        businesslicenseNumber: null,
        businesslicenseUrl: null,
        legalRepresentative: null,
        createdAt: null,
        updatedAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "承租人姓名不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "承租人身份证不能为空", trigger: "blur" }
        ],
        userPhoneNumber: [
          { required: true, message: "承租人手机号不能为空", trigger: "blur" }
        ],
        alipayUid: [
          { required: true, message: "支付宝账号信息 (租借商品用户的支付宝uid)不能为空", trigger: "blur" }
        ],
        leaseCorpName: [
          { required: true, message: "出租企业名称不能为空", trigger: "blur" }
        ],
        leaseCorpId: [
          { required: true, message: "出租企业统一社会信用代码不能为空", trigger: "blur" }
        ],
        leaseCorpOwnerName: [
          { required: true, message: "出租法定代表人姓名不能为空", trigger: "blur" }
        ],
        lesseeType: [
          { required: true, message: "租赁方类别 (1.企业用户, 2.个人用户)不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询承租人信息列表 */
    getList() {
      this.loading = true;
      listLesseeInfo(this.queryParams).then(response => {
        this.lesseeInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userName: null,
        userId: null,
        userPhoneNumber: null,
        userType: null,
        certValidDate: null,
        alipayUid: null,
        userOpenId: null,
        merchantAppId: null,
        leaseCorpName: null,
        leaseCorpId: null,
        leaseCorpOwnerName: null,
        lesseeType: null,
        leasedEnterprise: null,
        userImageUrl: null,
        userBackImageUrl: null,
        registeredTelephoneNumber: null,
        actualControllerId: null,
        actualControllerNumber: null,
        actualControllerName: null,
        actualControllerImageUrl: null,
        actualControllerBackImageUrl: null,
        businesslicenseNumber: null,
        businesslicenseUrl: null,
        legalRepresentative: null,
        createdAt: null,
        updatedAt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加承租人信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLesseeInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改承租人信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLesseeInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLesseeInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除承租人信息编号为"' + ids + '"的数据项？').then(function() {
        return delLesseeInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('trans/lesseeInfo/export', {
        ...this.queryParams
      }, `lesseeInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
